package com.atguigu.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/fruit")
public class Demo02ControllerMapping {

    @DeleteMapping("/test/method")
    @ResponseBody
    public String mappingDelete() {
        return "ok delete";
    }

    @PutMapping("/test/method")
    @ResponseBody
    public String mappingPut() {
        return "ok put";
    }

    @PostMapping("/test/method")
    @ResponseBody
    public String mappingPost() {
        return "ok post";
    }

    // @RequestMapping(value = "/test/method", method = RequestMethod.GET)
    @GetMapping("/test/method")
    @ResponseBody
    public String mappingGet() {
        return "ok get";
    }

    @RequestMapping("/apple")
    @ResponseBody
    public String apple() {
        return "ok apple";
    }

    // /fruit/orange
    @RequestMapping("orange")
    @ResponseBody
    public String orange() {
        return "ok orange";
    }

    // 一个 * 号匹配 URL 地址中的一层
    // /fruit/apple     匹配
    // /fruit/orange    匹配
    // /fruit/banana    匹配
    // /fruit/banana/good   不匹配
    @RequestMapping("/*")
    @ResponseBody
    public String fruit() {
        System.out.println("/* fruit() 方法执行了");
        return "ok";
    }

    // 两个 * 号匹配 URL 地址中的任意层
    // /fruit/apple     匹配
    // /fruit/orange    匹配
    // /fruit/banana    匹配
    // /fruit/banana/good   匹配
    @RequestMapping("/**")
    @ResponseBody
    public String fruit2() {
        System.out.println("/** fruit2() 方法执行了");
        return "ok";
    }
}
